package collection.homework.Collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 迭代器
 */
public class IteratorDemo {
    public static void main(String[] args) {
        Collection<String> a = new ArrayList<>();
        a.add("one");
        a.add("#");
        a.add("two");
        a.add("#");
        a.add("three");
        a.add("#");
        a.add("four");
        System.out.println(a);//[one, #, two, #, three, #, four]

        Iterator<String> it = a.iterator();
        while (it.hasNext()){
            String str = it.next();
            System.out.println(str);
            if ("#".equals(str)){
                it.remove();
            }
        }
        System.out.println(a);//[one, two, three, four]
    }
}
